<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/mayioa/css/mayioa-ui.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/datapicker/datepicker3.css}" rel="stylesheet"/>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-plan-config-edit" th:object="${planConfig}">
			<input name="planCfgDeptId"  type="hidden"  th:field="*{planCfgDeptId}" id="treeId"/>

			<input name="planCfgId"  type="hidden"  th:field="*{planCfgId}" id="planCfgId"/>

			<div class="form-group">
				<label class="col-sm-3 control-label">计划名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="planCfgName" id="planCfgName" th:field="*{planCfgName}">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">部门名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="planDeptName" onclick="selectDeptTree()" readonly="true" id="treeName" th:field="*{planDeptName}">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">计划项目类型：</label>
				<div class="col-sm-8">
					<select id="planCfgType" class="form-control m-b" th:with="type=${@dict.getType('plan_detail_type')}" th:field="*{planCfgType}">
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
					</select>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">计划流程：</label>
				<div class="col-sm-8">
					<select id="planCfgFlowName" name="planCfgFlowName" class="form-control m-b" th:field="*{planCfgFlowId}">
						<option value="">-&#45;&#45;请选择-&#45;&#45;</option>
						<option th:each="flow:${flowList}" th:value="${flow['planFlowId']}" th:text="${flow['planFlowName']}"></option>
					</select>
				</div>
			</div>

            <div class="form-group">
                <label class="col-sm-3 control-label">计划约束：</label>
                <div class="col-sm-8">
                    <select id="planCfgCond" name="planCfgCond" class="form-control select2-hidden-accessible" multiple="">
                        <option th:each="cond:${conditions}" th:value="${cond.planCstrId}" th:text="${cond.planCstrName}" th:selected="${cond.flag}"></option>
                    </select>
                </div>
            </div>

			<div class="form-group">
				<label class="col-sm-3 control-label">发布状态：</label>
				<div class="col-sm-8">
					<select id="planCfgStatus" class="form-control m-b" th:with="type=${@dict.getType('plan_release_status')}" disabled="true">
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{planCfgStatus}"></option>
					</select>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">通过分数：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="planCfgPassScore" id="planCfgPassScore" th:field="*{planCfgPassScore}">
				</div>
			</div>


			<div class="col-md-12">
				<div class="form-group">
					<label class="col-sm-3 control-label">计划开始时间：</label>
					<div class="col-sm-8">
						<div class="form-group">
							<div class="input-group date"> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
								<input type="text" id="planCfgStartTime" name="planCfgStartTime" class="form-control"  th:value="${#dates.format(planConfig.planCfgStartTime, 'yyyy-MM-dd')}">
							</div>
						</div>
					</div>
				</div>
			</div>

			<div class="col-md-12">
				<div class="form-group">
					<label class="col-sm-3 control-label">计划结束时间：</label>
					<div class="col-sm-8">
						<div class="form-group">
							<div class="input-group date"> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
								<input type="text" id="planCfgEndTime" name="planCfgEndTime" class="form-control"  th:value="${#dates.format(planConfig.planCfgEndTime, 'yyyy-MM-dd')}">
							</div>
						</div>
					</div>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<textarea id="planCfgRemark" name="planCfgRemark" class="form-control">[[*{planCfgRemark}]]</textarea>
				</div>
			</div>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/select/select2.js}"></script>
	<script th:src="@{/js/jquery-ui-1.10.4.min.js}"></script>
	<script th:src="@{/ajax/libs/iCheck/icheck.min.js}"></script>
	<script th:src="@{/ajax/libs//datapicker/bootstrap-datepicker.js}"></script>
	<script th:src="@{/ajax/libs/beautifyhtml/beautifyhtml.js}"></script>
	<script>
		 $("#planCfgStartTime").datepicker({
			todayBtn: "linked",
			keyboardNavigation: !1,
			forceParse: !1,
			calendarWeeks: !0,
			autoclose: !0
		});

		 $("#planCfgEndTime").datepicker({
			todayBtn: "linked",
			keyboardNavigation: !1,
			forceParse: !1,
			calendarWeeks: !0,
			autoclose: !0
		});

        $("#form-plan-config-edit").validate({
        	rules:{
        		planCfgName:{
        			required:true,
        			maxlength: 255,
        			remote: {
                        url: ctx + "plan/config/checkPlanCfgNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                        	"planCfgId": function() {
                        		return $("#planCfgId").val();
                            },
                			"planCfgName": function() {
                                return $.common.trim($("#planCfgName").val());
                            }
                        },
                        dataFilter: function(data, type) {
                        	return $.validate.unique(data);
                        }
                    }
        		},
        		planDeptName:{
        			required:true
        		},
        		planCfgPassScore:{
        			required:true,
        			number:true
        		},
        		planCfgStartTime:{
        			required:true
        		},
        		planCfgEndTime:{
        			required:true
        		}
            },
            messages: {
				"planCfgName": {
					remote: "计划名称已经存在"
				}
			}
        });
        
        function submitHandler() {
	        if ($.validate.form()) {
	        	edit();
	        }
	    }

        function edit() {
        	var planCfgId = $("input[name='planCfgId']").val();
        	var planCfgDeptId = $("input[name='planCfgDeptId']").val();
        	var planCfgName = $("input[name='planCfgName']").val();
        	var planCfgType = $("#planCfgType option:selected").val();
        	var planCfgFlowId = $("#planCfgFlowName option:selected").val();
        	var planCfgStatus = $("#planCfgStatus option:selected").val();
        	var planCfgPassScore = $("input[name='planCfgPassScore']").val();
			var planCfgStartTime = $("input[name='planCfgStartTime']").val();
        	var planCfgEndTime = $("input[name='planCfgEndTime']").val();
        	var planCfgRemark = $("#planCfgRemark").val();
        	var condIds = $.form.selectSelects("planCfgCond");

        	$.ajax({
        		cache : true,
        		type : "POST",
        		url : ctx + "plan/config/edit",
        		data : {
        			"planCfgId": planCfgId,
        			"planCfgDeptId": planCfgDeptId,
        			"planCfgName": planCfgName,
        			"planCfgStatus": planCfgStatus,
        			"planCfgType": planCfgType,
        			"planCfgFlowId": planCfgFlowId,
        			"planCfgPassScore": planCfgPassScore,
        			"planCfgStartTime": planCfgStartTime,
        			"planCfgEndTime": planCfgEndTime,
        			"planCfgRemark": planCfgRemark,
        			"condIds": condIds
        		},
        		async : false,
        		error : function(request) {
        			$.modal.alertError("系统错误");
        		},
        		success : function(data) {
        			$.operate.saveSuccess(data);
        		}
        	});
        }

        /*用户管理-修改-选择部门树*/
        function selectDeptTree() {
        	var deptId = $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
		    var options = {
				title: '选择部门',
				width: "380",
				url: url,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}
		
		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			<!--if ($.tree.notAllowParents(tree)) {-->
    			var body = layer.getChildFrame('body', index);
    			$("#treeId").val(body.find('#treeId').val());
    			$("#treeName").val(body.find('#treeName').val());
    			layer.close(index);
			<!--}-->
		}
    </script>
</body>
</html>
